
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream>

#include "host_graph_sw.h"

using namespace std;

graphInfo graphDataInfo;

//#define default_xclbin_name "/home/zyh/workspace8/hls_acceletor_4K64PE64Crossbar_v1/Emulation-SW/binary_container_1.xclbin"
//#define default_xclbin_name "/home/zyh/workspace8/hls_acceletor_4K64PE64Crossbar_v1/Emulation-HW/binary_container_1.xclbin"
#define default_xclbin_name "/home/zyh/workspace8/hls_acceletor_4K64PE64Crossbar_v1/Hardware/binary_container_1.xclbin"

//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_19_16.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_19_32.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_19_64.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_21_16.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_21_32.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_21_64.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_23_16.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_23_32.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_24_16.txt"
//#define default_graph_name "/home/zyh/PaRMAT-master/Release/rmat_24_32.txt"
//#define default_graph_name "/home/zyh/SnapDataset/soc-LiveJournal1.txt"
//#define default_graph_name "/home/zyh/SnapDataset/soc-pokec-relationships.txt"
//#define default_graph_name "/home/zyh/SnapDataset/web-Google.txt"
//#define default_graph_name "/home/zyh/SnapDataset/wiki-Talk.txt"
//#define default_graph_name "/home/zyh/SnapDataset/wiki-topcats.txt"

//#define default_graph_name "/home/zyh/SnapDataset/NetworkRepository/ca-hollywood-2009.mtx.pre"
//#define default_graph_name "/home/zyh/SnapDataset/com-orkut.txt.pre"
#define default_graph_name "/home/zyh/SnapDataset/NetworkRepository/soc-twitter-2010.mtx.uwpre.pre"

#include "host_run_one_iteration.h"
int main(int argc, char **argv) {

	//printf("sizeof(size_t)=%d\n",sizeof(size_t));return 0;
    char * xcl_file = default_xclbin_name;
    if (argc > 1)
    {
        xcl_file = argv[1];
    }

    std::string gName=default_graph_name;
    if (argc > 2)
    {
        gName = argv[2];
    }
    else
    {
        //gName = "wiki-talk";
    }
    std::string mode = "normal";
#if 0
    Graph* gptr = createGraph(gName, mode);
    CSR* csr    = new CSR(*gptr);
    csr->save2File(gName);
    free(gptr);
    return 0;
#endif



    DEBUG_PRINTF("start main\n");

    acceleratorInit("graph_fpga", xcl_file);

    acceleratorDataPrepare(gName, mode, &graphDataInfo);

    acceleratorDataPreprocess(&graphDataInfo);

    runoneiteration_init(&graphDataInfo);
    for (int runCounter = 0 ; runCounter < 10 ; runCounter ++){
    	//runoneiteration(&graphDataInfo,runCounter);
    }
    //return 0;

    bool fin=false;
    for (int runCounter = 0 ; runCounter < 30&&fin==false ; runCounter ++)
    {
    	fin=runoneiteration(&graphDataInfo,runCounter);

        double startStamp, endStamp;

        if(runCounter==0){
        	acceleratorSuperStep(0, &graphDataInfo);
        }
        startStamp = getCurrentTimestamp();

        acceleratorSuperStep(0, &graphDataInfo);

        endStamp = getCurrentTimestamp();

        /* profile */
        accelratorProfile(runCounter, runCounter, &graphDataInfo, endStamp - startStamp);
    }
    acceleratorDeinit();

    return 0;
}
